import sys
import time
from PySide6.QtWidgets import QApplication, QMainWindow, QGraphicsScene, QGraphicsView, QGraphicsEllipseItem
from PySide6.QtCore import QRectF
from PySide6.QtGui import QBrush, QColor

class 节点图形项(QGraphicsEllipseItem):
    def __init__(self, x, y):
        super().__init__()
        self.setRect(QRectF(x, y, 50, 50))
        self.setBrush(QBrush(QColor(255, 0, 0)))

class 主窗口(QMainWindow):
    def __init__(self):
        super().__init__()
        self.场景 = QGraphicsScene(self)
        self.视图 = QGraphicsView(self.场景, self)
        self.setCentralWidget(self.视图)
        self.节点列表 = []

    def 添加节点(self):
        start_time = time.time()
        for i in range(10000):
            x = i * 60
            y = i * 60
            节点 = 节点图形项(x, y)
            self.场景.addItem(节点)
            self.节点列表.append(节点)
        end_time = time.time()
        print(f"添加10000个节点耗时: {end_time - start_time} 秒")

if __name__ == "__main__":
    app = QApplication(sys.argv)

    窗口 = 主窗口()
    窗口.resize(800, 600)
    窗口.show()

    窗口.添加节点()

    sys.exit(app.exec())